package com.sergio.compress.dao.service;

import com.sergio.compress.dao.mapper.CpTestRepository;
import com.sergio.compress.dao.model.CpTestRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author : Sergio.D
 * @Description :
 * @CreateDate ：2023/6/15 11:36
 */
@Service
public class CpTestRecordService {

    public static String COLLECTION_NAME;

    @Autowired
    VNumService vNumService;

    @Autowired
    MongoTemplate mongoTemplate;

    @Autowired
    CpTestRepository cpTestRepository;

    private static boolean inited = false;

    public void init() {
        vNumService.init();
        COLLECTION_NAME = "cp_record_" + VNumService.versionNum;
        System.out.println("设置当前存档 COLLECTION_NAME  : " + COLLECTION_NAME);

    }

    public void save(CpTestRecord result) {
        if (!inited) {
            init();
            inited = true;
        }
//        CommonUtil.setCollectionName(CpTest.class,COLLECTION_NAME);
        mongoTemplate.save(result, COLLECTION_NAME);
    }


}
